package com.smec.moblie;

import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;

import com.blankj.utilcode.util.Utils;
import com.smec.moblie.glocation.LocationService;
import com.smec.remes.smecManager.SmecRetrofit.RetrofitServiceManager;

import org.litepal.LitePalApplication;

import cn.jpush.android.api.JPushInterface;

public class SMECApplication extends LitePalApplication {

    private static Context mContext;
    @Override
    public void onCreate() {
        super.onCreate();
        JPushInterface.init(this); // 初始化 JPush
        startAlarm();
        mContext=getApplicationContext();
        RetrofitServiceManager.init();
        Utils.init(mContext);
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
//        MultiDex.install(this);
//        android.support.multidex.MultiDex.install(this);
    }

    public static Context getContext() {
        return mContext;
    }

    public void startAlarm() {
        /**
         首先获得系统服务
         */
        AlarmManager am = (AlarmManager)
                getSystemService(Context.ALARM_SERVICE);

        /** 设置闹钟的意图，调用一个服务，该服务功能就是获取位置并且上传*/
        Intent intent = new Intent(this, LocationService.class);
        PendingIntent pendSender = PendingIntent.getService(this, 0, intent, 0);
        am.cancel(pendSender);

        /**AlarmManager.RTC_WAKEUP 这个参数表示系统会唤醒进程；我设置的间隔时间是30秒 */
        am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 30 * 1000, pendSender);
    }
}

